package threads;

import java.util.Timer;
import java.util.TimerTask;

public class TimerExample {

	public static void main(String args[]) {
		final Timer timer = new Timer();
		// what will happen if we create daemon timer?
		//final Timer timer = new Timer(true);

		TimerTask task = new TimerTask() {
			public void run() {
				System.out.println("Time's up !");
				// what will happen if we dont cancel the timer 
				// timer.cancel(); // Stop the timer
			}
		};
		
		timer.schedule(task, 2 * 1000);
		// what will happen if we schedule the same task again?
		timer.schedule(task, 3 * 1000);

		System.out.println("I am waiting !");
	}

}
